package org.yzhzc.common.security.config;

import org.yzhzc.common.security.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

// 配置 WebMvc，注册拦截器
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private TokenInterceptor tokenInterceptor;  // 注入自定义的 Token 拦截器

    // 注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor)  // 添加 Token 拦截器
                .excludePathPatterns("/**/login", "/**/test/**")  // 排除登录和测试接口
                .addPathPatterns("/**");  // 拦截所有其他接口
    }
}
